package com.rgp.servicedriveruser.controller;

import com.rgp.internalcommon.common.CommonStatusEnum;
import com.rgp.internalcommon.dto.ResponseResult;
import com.rgp.internalcommon.response.DriverInfoResponse;
import com.rgp.internalcommon.response.DriverVerificationResponse;
import com.rgp.servicedriveruser.pojo.DriverUser;
import com.rgp.servicedriveruser.service.DriverUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author nhp
 * @version 1.0
 * @description TODO
 * @date 2024-04-16 17:11
 */
@RestController
public class DriverUserController {

    @Autowired
    private DriverUserService driverUserService;

    @PostMapping("/users")
    public ResponseResult addDriver(@RequestBody DriverUser driverUser){
        //添加司机
        driverUserService.addDriverUser(driverUser);
        return ResponseResult.success();
    }

    @PutMapping("/users")
    public ResponseResult updateDriver(@RequestBody DriverUser driverUser){
        Integer integer = driverUserService.updateDriverUser(driverUser);
        if (!integer.equals(new Integer("1"))){
            return ResponseResult.fail(CommonStatusEnum.DRIVER_USER_UPDATE_ERROR);
        }
        return ResponseResult.success();
    }

    @GetMapping("/users/{phoneNum}")
    public ResponseResult<DriverVerificationResponse> getDriverByPhoneNum(@PathVariable("phoneNum") String phondNum){
        DriverVerificationResponse response =  driverUserService.getDriverByPhoneNum(phondNum);
        return ResponseResult.success(response);
    }

    @GetMapping("/drivers/{cityCode}/{state}")
    public ResponseResult<Boolean> judgeIfExistAvailableDrivers(@PathVariable("cityCode")String cityCode,@PathVariable("state") Integer state){
        return driverUserService.judgeIfExistAvailableDrivers(cityCode,state);
    }

    @GetMapping("/drivers/{driverId}")
    public ResponseResult<DriverInfoResponse> getDriverInfoByDriverId(@PathVariable("driverId")String driverId){
        return driverUserService.getDriverInfoByDriverId(driverId);
    }
}